#ifdef GL_ES
precision mediump float;
#endif

uniform float u_time;
uniform vec2 u_resolution;
uniform vec2 u_mouse;


struct Rect{
    vec2 size;
    vec2 origin;
    vec3 color;
} rect,rect1;

struct Circle{
    vec2 center;
    float radius;
    vec3 color;
} circle;



vec3 black = vec3(0.0);
vec3 white = vec3(1.,1.,1.);
vec3 yellow = vec3(1.,1.,0.);
vec3 cyan = vec3(.0,1.,1.);
vec3 red = vec3(1.,0.,0.);

bool rect_contains(in  Rect rect,vec2 point){
    float left = rect.origin.x - rect.size.x / 2.;
    float bottom = rect.origin.y - rect.size.y / 2.;
    float right = rect.origin.x + rect.size.x / 2.;
    float top = rect.origin.y + rect.size.y / 2.;
    return point.x >= left && point.x <= right && point.y >= bottom && point.y <= top;
}

bool circle_contains(in Circle circle,vec2 point){
    float dist = length(point - circle.center);
    return dist <= circle.radius;
}

void main(){
    vec2 st = gl_FragCoord.xy / u_resolution;

    // rect
    rect.origin = vec2(0.5,0.5);
    rect.size = vec2(0.1,0.1);
    rect.color = cyan;

    // rect1
    rect1.origin = vec2(0.7,0.7);
    rect1.size = vec2(0.2,0.2);
    rect1.color = red;

    // circle 
    circle.center = vec2(0.2,0.7);
    circle.radius = 0.1;
    circle.color = yellow;

    vec3 color = vec3(0.);
    if(circle_contains(circle,st)){
        color += circle.color;
    }
    if(rect_contains(rect,st)){
        color += rect.color;
    }
    if(rect_contains(rect1,st)){
        color += rect1.color;
    }



    // if(rect_contains(rect,st) || 
    //    rect_contains(rect1,st) ||
    //    circle_contains(circle,st)){
    //     color = vec3(1.0,.0,.0);
    // }else{
    //     color = vec3(1.0,1.0,1.0);
    // }

    // vec2 bl = smoothstep(vec2(0.),vec2(0.1),st);
    // vec2 tr = smoothstep(vec2(.0),vec2(0.2),1.-st);
    // vec3 color = vec3(bl.x * bl.y * tr.x * tr.y);
    gl_FragColor = vec4(color,1.);
}